package c.e.a.b.f.b;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import b.i.c.a;
import c.e.a.b.b.j.c;
import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;
import java.io.IOException;
import java.util.Calendar;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class j extends r5 {
    public long c;
    public String d;
    public Boolean e;
    public AccountManager f;
    public Boolean g;
    public long h;

    public j(u4 u4Var) {
        super(u4Var);
    }

    public final boolean r() {
        Calendar instance = Calendar.getInstance();
        this.c = TimeUnit.MINUTES.convert((long) (instance.get(16) + instance.get(15)), TimeUnit.MILLISECONDS);
        Locale locale = Locale.getDefault();
        String language = locale.getLanguage();
        Locale locale2 = Locale.ENGLISH;
        language = language.toLowerCase(locale2);
        String toLowerCase = locale.getCountry().toLowerCase(locale2);
        StringBuilder stringBuilder = new StringBuilder(String.valueOf(toLowerCase).length() + (String.valueOf(language).length() + 1));
        stringBuilder.append(language);
        stringBuilder.append("-");
        stringBuilder.append(toLowerCase);
        this.d = stringBuilder.toString();
        return false;
    }

    public final boolean s(Context context) {
        if (this.e == null) {
            this.e = Boolean.FALSE;
            try {
                PackageManager packageManager = context.getPackageManager();
                if (packageManager != null) {
                    packageManager.getPackageInfo("com.google.android.gms", AesLen.ROOTKEY_COMPONET_LEN);
                    this.e = Boolean.TRUE;
                }
            } catch (NameNotFoundException unused) {
            }
        }
        return this.e.booleanValue();
    }

    public final long t() {
        o();
        return this.c;
    }

    public final String u() {
        o();
        return this.d;
    }

    public final long v() {
        g();
        return this.h;
    }

    public final boolean w() {
        Boolean bool = Boolean.TRUE;
        String str = "com.google";
        Boolean bool2 = Boolean.FALSE;
        g();
        Objects.requireNonNull((c) this.a.n);
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - this.h > 86400000) {
            this.g = null;
        }
        Boolean bool3 = this.g;
        if (bool3 != null) {
            return bool3.booleanValue();
        }
        if (a.a(this.a.a, "android.permission.GET_ACCOUNTS") != 0) {
            d().j.a("Permission error checking for dasher/unicorn accounts");
            this.h = currentTimeMillis;
            this.g = bool2;
            return false;
        }
        if (this.f == null) {
            this.f = AccountManager.get(this.a.a);
        }
        try {
            Account[] accountArr = (Account[]) this.f.getAccountsByTypeAndFeatures(str, new String[]{"service_HOSTED"}, null, null).getResult();
            if (accountArr == null || accountArr.length <= 0) {
                Account[] accountArr2 = (Account[]) this.f.getAccountsByTypeAndFeatures(str, new String[]{"service_uca"}, null, null).getResult();
                if (accountArr2 != null && accountArr2.length > 0) {
                    this.g = bool;
                    this.h = currentTimeMillis;
                    return true;
                }
                this.h = currentTimeMillis;
                this.g = bool2;
                return false;
            }
            this.g = bool;
            this.h = currentTimeMillis;
            return true;
        } catch (AuthenticatorException | OperationCanceledException | IOException e) {
            d().g.b("Exception checking account types", e);
        }
    }
}
